package c.c.k.service.impl;

import c.c.k.pojo.Event;
import c.c.k.repository.EventRepository;
import c.c.k.service.EventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenck on 2022/3/19.
 */
@Service
@Slf4j
public class EventServiceImpl implements EventService {
    @Autowired
    private EventRepository eventRepository;

    @Override
    public void addEvent(Event event) {
        Event event1 = eventRepository.findByCodeAndAndDate(event.getCode(), event.getDate());
        if(event1 == null) {
            eventRepository.save(event);
        }
    }

    @Override
    public List<Event> listEvent(List<Long> stockIds, PageRequest request) {
//        return eventRepository.findAll(request).getContent();
        return eventRepository.listEvent(stockIds, request);
    }
}
